﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ArgusLib.Threading.Collections
{
	public class SynchronizedCollectionWrapper<T> : SynchronizedCollectionBase<T>
	{
		ICollection<T> collection;

		public SynchronizedCollectionWrapper(ICollection<T> collection)
			: this(collection, new object()) { }

		public SynchronizedCollectionWrapper(ICollection<T> collection, object syncRoot)
			: base(syncRoot)
		{
			this.collection = collection;
		}

		protected override ISynchronizedEnumerator<T> GetEnumeratorCore()
		{
			return new SynchronizedEnumeratorWrapper<T>(this.collection.GetEnumerator(), this.SyncRoot);
		}

		protected override int CountGetCore() { return this.collection.Count; }
		protected override bool IsReadOnlyGetCore() { return this.collection.IsReadOnly; }
		protected override void AddCore(T item) { this.collection.Add(item); }
		protected override void ClearCore() { this.collection.Clear(); }
		protected override bool ContainsCore(T item) { return this.collection.Contains(item); }
		protected override void CopyToCore(T[] array, int index) { this.collection.CopyTo(array, index); }
		protected override bool RemoveCore(T item) { return this.collection.Remove(item); }

		public int Count { get { return ((ICollection<T>)this).Count; } }
		public bool IsReadOnly { get { return ((ICollection<T>)this).IsReadOnly; } }

		public void Add(T item) { ((ICollection<T>)this).Add(item); }
		public void Clear() { ((ICollection<T>)this).Clear(); }
		public bool Contains(T item) { return ((ICollection<T>)this).Contains(item); }
		public void CopyTo(T[] array, int index) { ((ICollection<T>)this).CopyTo(array, index); }
		public bool Remove(T item) { return ((ICollection<T>)this).Remove(item); }
	}
}
